/**
 * 
 */
package org.swing.utility.input.action;

import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import javax.swing.Action;
import javax.swing.AbstractAction;

/**
 * @author Quynh Nhu
 * 
 */
public class ExitAction extends AbstractAction {
	public ExitAction() {
		super("Exit");
		putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
	}

	public void actionPerformed(ActionEvent e) {
		// Find the active frame before creating and dispatching the event

		for (Frame frame : Frame.getFrames()) {
			if (frame.isActive()) {
				WindowEvent windowClosing = new WindowEvent(frame,
						WindowEvent.WINDOW_CLOSING);
				frame.dispatchEvent(windowClosing);
			}
		}
	}
}
